home *** CD-ROM | disk | FTP | other *** search
- program wrong_oop;
-
- {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
- { Program to illustrate the need for Virtual Methods in }
- { object-oriented programming. Compare with RIGHTOOP.PAS }
- { }
- { WRONGOOP.PAS -> WRONGOOP.EXE R. Shaw 26.4.91 31.5.93 }
- {___________________________________________________________________}
-
- uses Crt;
-
- type
-
- staff = object
- Name : string;
- constructor Init(SurName : string );
- procedure script1; { }
- procedure script2; { These are all static procedures }
- procedure action1; { and can be inherited as they are.}
- procedure action2; { }
- end;
-
- junior = object( staff )
- procedure script1; {As static procedures, they will not }
- procedure script2; {override those inherited from staff }
- end;
-
- var
- LetterName : string;
-
- constructor staff.Init( SurName : string );
- begin
- Name := SurName;
- end;
-
- procedure staff.script1;
- begin
- writeln( Name,
- ': Please send the duplicated letters to all our customers.');
- writeln( ' If you have a problem, please ask me.');
- end;
-
- procedure staff.script2;
- begin
- LetterName := 'OD';
- writeln(Name,': The letter is headed ',LetterName,'.');
- writeln;
- end;
-
- procedure staff.action1;
- begin
- script1;
- end;
-
- procedure staff.action2;
- begin
- script2;
- end;
-
-
- procedure junior.script1;
- begin
- writeln;
- writeln( '< later >');
- writeln;
- writeln( Name, ': I do not know the letter to send for an overdraft' );
- writeln;
- end;
-
- procedure junior.script2;
- begin
- writeln( Name, ': Thank you. ');
- writeln;
- writeln( '< later still >' );
- writeln;
- writeln( Name, ': As you requested, I sent the letter headed ',LetterName,'.');
- end;
-
- {Main}
-
- var
- Young : junior;
- Old : staff;
-
- begin
- clrscr;
-
- Young.Init( 'NEWMAN' );
- Old.Init( 'SENIOR' );
-
- Old.action1;
- Young.action1;
- Old.action2;
- Young.action2;
-
- gotoXY(10,24);
- write('Press any key to conclude: ');
- repeat until keypressed;
- clrscr;
- end.
-
- { end of listing }
-